package com.eascs.gaczcontract.controller;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.alibaba.dubbo.config.annotation.Reference;
import com.eascs.admin.common.utils.StringUtils;
import com.eascs.admin.o2o.internal.entity.PubDditem;
import com.eascs.admin.o2o.internal.service.LoanapplyExpandService;
import com.eascs.admin.o2o.internal.service.PubDditemService;
import com.eascs.admin.o2o.internal.util.StatusContexts;
import com.eascs.admin.o2o.loan.entity.O2oLoanBkInfo;
import com.eascs.admin.o2o.loan.entity.O2oLoanGsInfo;
import com.eascs.admin.o2o.loan.entity.O2oLoanScInfo;
import com.eascs.admin.o2o.loan.entity.O2oLoanUserEntity;
import com.eascs.admin.o2o.loan.entity.O2oLoanapplyEntity;
import com.eascs.admin.o2o.loan.service.O2oLoanBkService;
import com.eascs.admin.o2o.loan.service.O2oLoanGsService;
import com.eascs.admin.o2o.loan.service.O2oLoanScService;
import com.eascs.admin.o2o.loan.service.O2oLoanUserService;
import com.eascs.admin.o2o.loan.service.O2oLoanapplyService;
import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.common.doc.word.WordBuilder;
import com.eascs.common.doc.word.WordPOIUntil;
import com.eascs.common.exception.RuntimeIOException;
import com.eascs.common.util.DateUtils;
import com.eascs.common.util.IoUtil;
import com.eascs.common.util.StringUtil;
import com.eascs.crm.nsEditDetail.entity.CustomerShopInfoEntity;
import com.eascs.crm.nsEditDetail.entity.CustomerShopInfoEntityNew;
import com.eascs.crm.nsEditDetail.entity.ManagementInfoEntity;
import com.eascs.crm.nsEditDetail.entity.O2oMainMonthInfoEntity;
import com.eascs.crm.nsEditDetail.entity.O2oMainShopInfoEntity;
import com.eascs.crm.nsEditDetail.service.CustomerShopInfoService;
import com.eascs.crm.nsEditDetail.service.IMainMonthInfoService;
import com.eascs.crm.nsEditDetail.service.IMainShopInfoService;
import com.eascs.crm.nsEditDetail.service.ManagementInfoService;
import com.eascs.gaczcontract.entity.CustomerBasicInfo;
import com.eascs.site.controller.BaseViewController;
import com.eascs.workflow.common.service.sys.SysOrgService;

/**
 * 银行申报节点下载推荐函、放款通知书
 * 
 * @author ycz
 *
 */
@Controller
@RequestMapping("/wordDownload")
public class BankWordRestContorller extends BaseViewController {
	protected final Logger logger = LoggerFactory.getLogger(getClass());
	@Autowired
	private O2oLoanapplyService loanService;
	@Autowired
	LoanapplyExpandService loanapplyExpandService;
	@Autowired
	PubDditemService pubDditemService;
	@Reference
	SysOrgService sysOrgService;
	@Autowired
	O2oLoanUserService loanUserService;
	@Autowired
	CustomerShopInfoService shopInfoService;
	@Autowired
	O2oLoanBkService o2oLoanBkService ;
	@Reference
	IMainShopInfoService mainShopInfoService;
	@Reference
	IMainMonthInfoService mainMonthInfoService;
	@Autowired
	private ManagementInfoService managementInfoService;
	@Autowired
	O2oLoanScService scService;
	@Autowired
	O2oLoanGsService gsService;
	
	/**
	 * 下载江西银行推荐函
	 * 
	 * @param httpServletResponse
	 * @param request
	 * @param loanapplyNo
	 */
	@RequestMapping(value = "/downloadRecommendation", method = RequestMethod.GET)
	public void downloadRecommendation(HttpServletResponse httpServletResponse, HttpServletRequest request, String loanapplyNo) {
		O2oLoanapplyEntity loanapply = loanService.findById(loanapplyNo);
		if (loanapply == null) {
			return;
		}
		O2oLoanUserEntity loanUserEntity = loanService.findLoanUserEntity(loanapplyNo, loanapply.getLoanId());
		CustomerBasicInfo customerBasicInfo = loanService.getCustomerEntityById(loanUserEntity.getId());
		// 最后需要生产的模板文件
		String classPathFiles = "/wordTemplate/JCBrecommendation.doc.xml";
		Map<String, Object> data = fillLoanAdvice(loanapplyNo,loanUserEntity,customerBasicInfo);
		OutputStream os = null;
		try {
			String outfile = "";
			outfile = loanUserEntity.getUserFullName() + "-推荐函.doc";
			if (request.getHeader("User-Agent").toUpperCase().indexOf("MSIE") > 0) {
				outfile = URLEncoder.encode(outfile, "UTF-8");
			} else {
				outfile = new String(outfile.getBytes("UTF-8"), "ISO8859-1");
			}
			os = httpServletResponse.getOutputStream();
			httpServletResponse.reset();
			httpServletResponse.setContentType("application/doc");
			httpServletResponse.setHeader("Content-Disposition", "attachment; filename=" + outfile);
			WordBuilder.buildDocFromXml(os, data, classPathFiles);
		} catch (IOException e) {
			throw new RuntimeIOException(e);
		} finally {
			IoUtil.close(os);
		}
	}
	
	/**
	 * 下载（国安村镇银行）放款通知书
	 * 
	 * @param httpServletResponse
	 * @param request
	 * @param loanapplyNo
	 */
	@RequestMapping(value = "/downFK_GACZloadLoanAdvice", method = RequestMethod.GET)
	public void downFK_GACZloadLoanAdvice(HttpServletResponse httpServletResponse, HttpServletRequest request, String loanapplyNo) {
		O2oLoanapplyEntity loanapply = loanService.findById(loanapplyNo);
		if (loanapply == null) {
			return;
		}
		O2oLoanUserEntity loanUserEntity = loanService.findLoanUserEntity(loanapplyNo, loanapply.getLoanId());
		CustomerBasicInfo customerBasicInfo = loanService.getCustomerEntityById(loanUserEntity.getId());
		// 最后需要生产的模板文件
		String classPathFiles = "/wordTemplate/FK_GACZloanAdvice.xml";
		Map<String, Object> data = fillFK_GACZLoanAdvice(loanapplyNo,loanUserEntity,customerBasicInfo);
		OutputStream os = null;
		try {
			String outfile = "";
			outfile = loanUserEntity.getUserFullName() + "-国安村镇银行放款通知书.doc";
			if (request.getHeader("User-Agent").toUpperCase().indexOf("MSIE") > 0) {
				outfile = URLEncoder.encode(outfile, "UTF-8");
			} else {
				outfile = new String(outfile.getBytes("UTF-8"), "ISO8859-1");
			}
			os = httpServletResponse.getOutputStream();
			httpServletResponse.reset();
			httpServletResponse.setContentType("application/doc");
			httpServletResponse.setHeader("Content-Disposition", "attachment; filename=" + outfile);
			WordBuilder.buildDocFromXml(os, data, classPathFiles);
		} catch (IOException e) {
			throw new RuntimeIOException(e);
		} finally {
			IoUtil.close(os);
		}
	}

	/**
	 * 下载（江西银行）放款通知书
	 * 
	 * @param httpServletResponse
	 * @param request
	 * @param loanapplyNo
	 */
	@RequestMapping(value = "/downloadLoanAdvice", method = RequestMethod.GET)
	public void downloadLoanAdvice(HttpServletResponse httpServletResponse, HttpServletRequest request, String loanapplyNo) {
		O2oLoanapplyEntity loanapply = loanService.findById(loanapplyNo);
		if (loanapply == null) {
			return;
		}
		O2oLoanUserEntity loanUserEntity = loanService.findLoanUserEntity(loanapplyNo, loanapply.getLoanId());
		CustomerBasicInfo customerBasicInfo = loanService.getCustomerEntityById(loanUserEntity.getId());
		// 最后需要生产的模板文件
		String classPathFiles = "/wordTemplate/JCBloanAdvice.doc";
		Map<String, String> data = fillRecommendation(loanapplyNo,loanUserEntity,customerBasicInfo);
		ByteArrayOutputStream outputStream =WordPOIUntil.downLoadDoc(classPathFiles, data);
		OutputStream os = null;
		try {
			String outfile = "";
			outfile = loanUserEntity.getUserFullName() + "-放款通知书.doc";
			if (request.getHeader("User-Agent").toUpperCase().indexOf("MSIE") > 0) {
				outfile = URLEncoder.encode(outfile, "UTF-8");
			} else {
				outfile = new String(outfile.getBytes("UTF-8"), "ISO8859-1");
			}
			os = httpServletResponse.getOutputStream();
			httpServletResponse.reset();
			httpServletResponse.setContentType("application/doc");
			httpServletResponse.setHeader("Content-Disposition", "attachment; filename=" + outfile);
			os.write(outputStream.toByteArray());
			os.flush();
		} catch (IOException e) {
			throw new RuntimeIOException(e);
		} finally {
			IoUtil.close(os);
		}
	}
	
	/**
	 * 下载（浦发广州分行）放款通知书
	 * 
	 * @author LMX
	 * @param httpServletResponse
	 * @param request
	 * @param loanapplyNo
	 */
	@RequestMapping(value = "/downSPDBGZloadLoanAdvice", method = RequestMethod.GET)
	public void downSPDBGZloadLoanAdvice(HttpServletResponse httpServletResponse, HttpServletRequest request, String loanapplyNo) {
		O2oLoanapplyEntity loanapply = loanService.findById(loanapplyNo);
		if (loanapply == null) {
			return;
		}
		O2oLoanUserEntity loanUserEntity = loanService.findLoanUserEntity(loanapplyNo, loanapply.getLoanId());
		CustomerBasicInfo customerBasicInfo = loanService.getCustomerEntityById(loanUserEntity.getId());
		// 最后需要生产的模板文件
		String classPathFiles = "/wordTemplate/SPDBGZloanAdvice.doc";
		Map<String, String> data = fillSPDBGZRecommendation(loanapplyNo,loanUserEntity,customerBasicInfo);
		ByteArrayOutputStream outputStream =WordPOIUntil.downLoadDoc(classPathFiles, data);
		OutputStream os = null;
		try {
			String outfile = "";
			outfile = loanUserEntity.getUserFullName() + "-放款申请审批表.doc";
			if (request.getHeader("User-Agent").toUpperCase().indexOf("MSIE") > 0) {
				outfile = URLEncoder.encode(outfile, "UTF-8");
			} else {
				outfile = new String(outfile.getBytes("UTF-8"), "ISO8859-1");
			}
			os = httpServletResponse.getOutputStream();
			httpServletResponse.reset();
			httpServletResponse.setContentType("application/doc");
			httpServletResponse.setHeader("Content-Disposition", "attachment; filename=" + outfile);
			os.write(outputStream.toByteArray());
			os.flush();
		} catch (IOException e) {
			throw new RuntimeIOException(e);
		} finally {
			IoUtil.close(os);
		}
	}
	/**
	 * 下载（浦发济南分行）放款通知书
	 * 
	 * @author LMX
	 * @param httpServletResponse
	 * @param request
	 * @param loanapplyNo
	 */
	@RequestMapping(value = "/downSPDBJNloadLoanAdvice", method = RequestMethod.GET)
	public void downSPDBJNloadLoanAdvice(HttpServletResponse httpServletResponse, HttpServletRequest request, String loanapplyNo) {
		O2oLoanapplyEntity loanapply = loanService.findById(loanapplyNo);
		if (loanapply == null) {
			return;
		}
		O2oLoanUserEntity loanUserEntity = loanService.findLoanUserEntity(loanapplyNo, loanapply.getLoanId());
		CustomerBasicInfo customerBasicInfo = loanService.getCustomerEntityById(loanUserEntity.getId());
		// 最后需要生产的模板文件
		String classPathFiles = "/wordTemplate/SPDBJNloanAdvice.doc";
		Map<String, String> data = fillSPDBJNRecommendation(loanapplyNo,loanUserEntity,customerBasicInfo);
		ByteArrayOutputStream outputStream =WordPOIUntil.downLoadDoc(classPathFiles, data);
		OutputStream os = null;
		try {
			String outfile = "";
			outfile = loanUserEntity.getUserFullName() + "-放款申请审批表.doc";
			if (request.getHeader("User-Agent").toUpperCase().indexOf("MSIE") > 0) {
				outfile = URLEncoder.encode(outfile, "UTF-8");
			} else {
				outfile = new String(outfile.getBytes("UTF-8"), "ISO8859-1");
			}
			os = httpServletResponse.getOutputStream();
			httpServletResponse.reset();
			httpServletResponse.setContentType("application/doc");
			httpServletResponse.setHeader("Content-Disposition", "attachment; filename=" + outfile);
			os.write(outputStream.toByteArray());
			os.flush();
		} catch (IOException e) {
			throw new RuntimeIOException(e);
		} finally {
			IoUtil.close(os);
		}
	}
	
	/**
	 * 下载（齐鲁银行）放款通知书
	 * 
	 * @author LMX
	 * @param httpServletResponse
	 * @param request
	 * @param loanapplyNo
	 */
	@RequestMapping(value = "/downQLBloadLoanAdvice", method = RequestMethod.GET)
	public void downQLBloadLoanAdvice(HttpServletResponse httpServletResponse, HttpServletRequest request, String loanapplyNo) {
		O2oLoanapplyEntity loanapply = loanService.findById(loanapplyNo);
		if (loanapply == null) {
			return;
		}
		O2oLoanUserEntity loanUserEntity = loanService.findLoanUserEntity(loanapplyNo, loanapply.getLoanId());
		CustomerBasicInfo customerBasicInfo = loanService.getCustomerEntityById(loanUserEntity.getId());
		// 最后需要生产的模板文件
		String classPathFiles = "/wordTemplate/QLBloanAdvice.doc";
		Map<String, String> data = fillQLBRecommendation(loanapplyNo,loanUserEntity,customerBasicInfo);
		ByteArrayOutputStream outputStream =WordPOIUntil.downLoadDoc(classPathFiles, data);
		OutputStream os = null;
		try {
			String outfile = "";
			outfile = loanUserEntity.getUserFullName() + "-齐鲁银行放款通知书.doc";
			if (request.getHeader("User-Agent").toUpperCase().indexOf("MSIE") > 0) {
				outfile = URLEncoder.encode(outfile, "UTF-8");
			} else {
				outfile = new String(outfile.getBytes("UTF-8"), "ISO8859-1");
			}
			os = httpServletResponse.getOutputStream();
			httpServletResponse.reset();
			httpServletResponse.setContentType("application/doc");
			httpServletResponse.setHeader("Content-Disposition", "attachment; filename=" + outfile);
			os.write(outputStream.toByteArray());
			os.flush();
		} catch (IOException e) {
			throw new RuntimeIOException(e);
		} finally {
			IoUtil.close(os);
		}
	}
	
	/**
	 * 下载（国安村镇银行）推荐函
	 * 
	 * @author LMX
	 * @param httpServletResponse
	 * @param request
	 * @param loanapplyNo
	 */
	@RequestMapping(value = "/downGACZloadLoanAdvice", method = RequestMethod.GET)
	public void downGACZloadLoanAdvice(HttpServletResponse httpServletResponse, HttpServletRequest request, String loanapplyNo) {
		O2oLoanapplyEntity loanapply = loanService.findById(loanapplyNo);
		if (loanapply == null) {
			return;
		}
		O2oLoanUserEntity loanUserEntity = loanService.findLoanUserEntity(loanapplyNo, loanapply.getLoanId());
		CustomerBasicInfo customerBasicInfo = loanService.getCustomerEntityById(loanUserEntity.getId());
		// 最后需要生产的模板文件
		String classPathFiles = "/wordTemplate/GACZloanAdvice.doc";
		Map<String, String> data = fillGACZRecommendation(loanapplyNo,loanUserEntity,customerBasicInfo);
		ByteArrayOutputStream outputStream =WordPOIUntil.downLoadDoc(classPathFiles, data);
		OutputStream os = null;
		try {
			String outfile = "";
			outfile = loanUserEntity.getUserFullName() + "-国安村镇银行推荐函打印版.doc";
			if (request.getHeader("User-Agent").toUpperCase().indexOf("MSIE") > 0) {
				outfile = URLEncoder.encode(outfile, "UTF-8");
			} else {
				outfile = new String(outfile.getBytes("UTF-8"), "ISO8859-1");
			}
			os = httpServletResponse.getOutputStream();
			httpServletResponse.reset();
			httpServletResponse.setContentType("application/doc");
			httpServletResponse.setHeader("Content-Disposition", "attachment; filename=" + outfile);
			os.write(outputStream.toByteArray());
			os.flush();
		} catch (IOException e) {
			throw new RuntimeIOException(e);
		} finally {
			IoUtil.close(os);
		}
	}
	
	/**
	 * 下载（郑州银行）放款通知书
	 * 
	 * @author LMX
	 * @param httpServletResponse
	 * @param request
	 * @param loanapplyNo
	 */
	@RequestMapping(value = "/downZZBloadLoanAdvice", method = RequestMethod.GET)
	public void downZZBloadLoanAdvice(HttpServletResponse httpServletResponse, HttpServletRequest request, String loanapplyNo) {
		O2oLoanapplyEntity loanapply = loanService.findById(loanapplyNo);
		if (loanapply == null) {
			return;
		}
		O2oLoanUserEntity loanUserEntity = loanService.findLoanUserEntity(loanapplyNo, loanapply.getLoanId());
		CustomerBasicInfo customerBasicInfo = loanService.getCustomerEntityById(loanUserEntity.getId());
		// 最后需要生产的模板文件
		String classPathFiles = "/wordTemplate/ZZBloanAdvice.doc";
		Map<String, String> data = fillZZBRecommendation(loanapplyNo,loanUserEntity,customerBasicInfo);
		ByteArrayOutputStream outputStream =WordPOIUntil.downLoadDoc(classPathFiles, data);
		OutputStream os = null;
		try {
			String outfile = "";
			outfile = loanUserEntity.getUserFullName() + "-担保确认及提请出账通知书(郑州银行)打印版.doc";
			if (request.getHeader("User-Agent").toUpperCase().indexOf("MSIE") > 0) {
				outfile = URLEncoder.encode(outfile, "UTF-8");
			} else {
				outfile = new String(outfile.getBytes("UTF-8"), "ISO8859-1");
			}
			os = httpServletResponse.getOutputStream();
			httpServletResponse.reset();
			httpServletResponse.setContentType("application/doc");
			httpServletResponse.setHeader("Content-Disposition", "attachment; filename=" + outfile);
			os.write(outputStream.toByteArray());
			os.flush();
		} catch (IOException e) {
			throw new RuntimeIOException(e);
		} finally {
			IoUtil.close(os);
		}
	}
	
	
	/**
	 * 下载（中旅银行）放款通知书
	 * 
	 * @param httpServletResponse
	 * @param request
	 * @param loanapplyNo
	 */
	@RequestMapping(value = "/downZLBloadLoanAdvice", method = RequestMethod.GET)
	public void downZLBloadLoanAdvice(HttpServletResponse httpServletResponse, HttpServletRequest request, String loanapplyNo) {
		O2oLoanapplyEntity loanapply = loanService.findById(loanapplyNo);
		if (loanapply == null) {
			return;
		}
		O2oLoanUserEntity loanUserEntity = loanService.findLoanUserEntity(loanapplyNo, loanapply.getLoanId());
		CustomerBasicInfo customerBasicInfo = loanService.getCustomerEntityById(loanUserEntity.getId());
	
		O2oLoanBkInfo bkInfo = o2oLoanBkService.getEntity(loanapplyNo);
		// 最后需要生产的模板文件
		String classPathFiles = "/wordTemplate/ZLBloanAdvice.doc";
		Map<String, String> data = fillZLBRecommendation(loanapplyNo,loanUserEntity,customerBasicInfo,bkInfo);
		ByteArrayOutputStream outputStream =WordPOIUntil.downLoadDoc(classPathFiles, data);
		OutputStream os = null;
//		try {
//			String outfile = "";
//			outfile = "中旅银行带数据合同.doc";
//			if (request.getHeader("User-Agent").toUpperCase().indexOf("MSIE") > 0) {
//				outfile = URLEncoder.encode(outfile, "UTF-8");
//			} else {
//				outfile = new String(outfile.getBytes("UTF-8"), "ISO8859-1");
//			}
//			os = httpServletResponse.getOutputStream();
//			httpServletResponse.reset();
//			httpServletResponse.setContentType("application/doc");
//			httpServletResponse.setHeader("Content-Disposition", "attachment; filename=" + outfile);
//			WordBuilder.buildDocFromXml(os, data, classPathFiles);
//		} catch (IOException e) {
//			throw new RuntimeIOException(e);
//		} finally {
//			IoUtil.close(os);
//		}
		try {
			String outfile = "";
			outfile = loanUserEntity.getUserFullName() + "-放款通知书.doc";
			if (request.getHeader("User-Agent").toUpperCase().indexOf("MSIE") > 0) {
				outfile = URLEncoder.encode(outfile, "UTF-8");
			} else {
				outfile = new String(outfile.getBytes("UTF-8"), "ISO8859-1");
			}
			os = httpServletResponse.getOutputStream();
			httpServletResponse.reset();
			httpServletResponse.setContentType("application/doc");
			httpServletResponse.setHeader("Content-Disposition", "attachment; filename=" + outfile);
			os.write(outputStream.toByteArray());
			os.flush();
		} catch (IOException e) {
			throw new RuntimeIOException(e);
		} finally {
			IoUtil.close(os);
		}
	}
	
	/**
	 * 填充（江西银行）放款通知书
	 * @param loanapplyNo
	 * @param basic
	 * @param customerBasicInfo
	 * @return
	 */
	private Map<String, String> fillRecommendation(String loanapplyNo,O2oLoanUserEntity basic,CustomerBasicInfo customerBasicInfo) {
		Map<String, String> data = new HashMap<>();
		O2oLoanapplyEntity loanapply = loanService.findById(loanapplyNo);
		if (loanapply == null) {
			return data;
		}
		NumberFormat nf = new DecimalFormat("#0.####");
		if (basic != null) {
			data.put("${loanName}", basic.getUserFullName());// 借款人
			data.put("${idCard}", basic.getDocumentNo());// 身份证号码
		}
		if (loanapply != null) {
			if (!"".equals(loanapply.getEaMount()) && loanapply.getEaMount() != null) {
//				data.put("${eaMount}", String.valueOf(loanapply.getEaMount().divide(new BigDecimal(10000)).intValue()));// 银行批复金额
				data.put("${eaMount}", nf.format(loanapply.getEaMount().divide(new BigDecimal(10000))));// 银行批复金额【万元】
			}
			data.put("${loanTerm}", String.valueOf(loanapply.getLoanTerm()));// 借款期限
		}
		return data;
	}
	
	/**
	 * 填充（中旅银行）放款通知书
	 * @param loanapplyNo
	 * @param basic
	 * @param customerBasicInfo
	 * @param shop
	 * @return
	 */
	private Map<String, String> fillZLBRecommendation(String loanapplyNo,O2oLoanUserEntity basic,CustomerBasicInfo customerBasicInfo,O2oLoanBkInfo bkInfo ) {
		Map<String, String> data = new HashMap<>();
		O2oLoanapplyEntity loanapply = loanService.findById(loanapplyNo);
		ManagementInfoEntity ma=managementInfoService.getByLoanNo(loanapplyNo);
		if (loanapply == null) {
			return data;
		}
//		data.put("licenceName", shop.getLicenceName());// 营业执照名字
		NumberFormat nf = new DecimalFormat("#0.####");
		if (basic != null) {
			data.put("${loanName}", basic.getUserFullName());// 借款人
			data.put("${idCard}", basic.getDocumentNo());// 身份证号码
		}
		String loanmMy=" ";
		if (ma!=null) {
			if (ma.getCapital()!=null) {
				loanmMy = nf.format(ma.getCapital().divide(new BigDecimal(10000)));// 年营业额（万元）,无需保留小数点
//				data.put("${loanmMy}", ma.getCapital().divide(new BigDecimal(10000)).toString());// 年营业额
			}
			
		}
		data.put("${loanmMy}",loanmMy);
		if (loanapply != null) {
			if (!"".equals(loanapply.getEaMount()) && loanapply.getEaMount() != null) {
				data.put("${eaMount}", nf.format(loanapply.getEaMount().divide(new BigDecimal(10000))));// 银行批复金额【万元】
			}
			data.put("${loanTerm}", String.valueOf(loanapply.getLoanTerm()));// 借款期限
			if (loanapply.getRepayMentway() != null) {// 还款方式
				if (loanapply.getRepayMentway().equals("AKT")) {
					data.put("${repayMentway}", "等额本金");// 还款方式
//					data.put("repayMentwayNo", "(2)");
				} else if (loanapply.getRepayMentway().equals("RMT")) {
					data.put("${repayMentway}", "按月付息，到期还本");// 还款方式
//					data.put("repayMentwayNo", "(1)");
				} else {
					data.put("${repayMentway}", "等额本息");// 还款方式
//					data.put("repayMentwayNo", "(2)");
				}
			}
		}
		
		// 渠道数据
		String startCoopDate = "";//项目合作年限
		if (loanapply.getLoanType().equals(StatusContexts.LOAN_TYPE_BP)
				|| loanapply.getLoanType().equals(StatusContexts.LOAN_TYPE_BP_JX)
				|| loanapply.getLoanType().equals(StatusContexts.LOAN_TYPE_BK)) {// 终端贷、流通贷-厂家、流通贷-经销商:/rmongo/bk_info_view
			O2oLoanBkInfo bkInfo2 = o2oLoanBkService.getEntity(loanapplyNo);
			if (bkInfo2 != null) {
				if (bkInfo2.getStartCoopDate() != null) {
					startCoopDate = new SimpleDateFormat("yyyy-MM-dd").format(bkInfo2.getStartCoopDate());// 与渠道企业合作起始时间
				} 
			} 
		} else if (loanapply.getLoanType().equals(StatusContexts.LOAN_TYPE_SC)) {// 流通贷-商超:/rmongo/sc_info_lno;loanType=='SC'
			O2oLoanScInfo scInfo = scService.getLoanapplyNo(loanapplyNo);
			if (scInfo != null) {
				if (scInfo.getWhitelistTime() != null) {
					startCoopDate = new SimpleDateFormat("yyyy-MM-dd").format(scInfo.getWhitelistTime());// 与白名单内商超合作开始时间
				} 
			} 
		} else if (loanapply.getLoanType().equals(StatusContexts.LOAN_TYPE_SG)) {// 流通贷-蔬果:/rmongo/gs_info_lno
			O2oLoanGsInfo gsInfo = gsService.getLoanapplyNo(loanapplyNo);
			if (gsInfo != null) {
				if (gsInfo.getStartOperateTime() != null) {
					startCoopDate = new SimpleDateFormat("yyyy-MM-dd").format(gsInfo.getStartOperateTime());// 本市场经营开始时间
				}
			}
		}
		data.put("${startCoopDate}", startCoopDate);
		
		String loanHz=" ";
		if (bkInfo != null) {		

			if (bkInfo.getMonthPrice() != null) {
				loanHz=nf.format(bkInfo.getMonthPrice().divide(new BigDecimal(10000)));
//				data.put("${loanHz}", nf.format(bkInfo.getMonthPrice().divide(new BigDecimal(10000))));// 与怡亚通月均合作金额（万元）
			} 
		}
		
		data.put("${loanHz}",loanHz);
		return data;
	}
	
	/**
	 * 填充（浦发广州分行）放款通知书
	 * @param loanapplyNo
	 * @return
	 */
	private Map<String, String> fillSPDBGZRecommendation(String loanapplyNo,O2oLoanUserEntity basic,CustomerBasicInfo customerBasicInfo) {
		Map<String, String> data = new HashMap<>();
		O2oLoanapplyEntity loanapply = loanService.findById(loanapplyNo);
		if (loanapply == null) {
			return data;
		}
//		NumberFormat nf = new DecimalFormat(",###.00");
		NumberFormat nf = new DecimalFormat("#0.####");
		O2oLoanUserEntity mate = loanUserService.findSpouseId(basic.getLoanId(), loanapplyNo);//配偶
		O2oLoanUserEntity guarantor = loanUserService.queryDBById(loanapplyNo);//担保人
		CustomerShopInfoEntity shop = new CustomerShopInfoEntity();
		List<CustomerShopInfoEntity> infoList = shopInfoService.list(loanapplyNo);//门店
		if (!infoList.isEmpty()) {
			if (infoList.size() > 1) {
				for (CustomerShopInfoEntity shopInfo : infoList) {
					if (shopInfo.getShoptype().equals("MAN")) {// 客户主门店里面的营业面积
						shop = shopInfo;
					}
				}
			} else {
				shop = infoList.get(0);
			}
		}
		if (shop != null) {
			if (shop.getBusinessarea() != null) {
				data.put("${businessarea}", String.valueOf(shop.getBusinessarea()));// 客户主门店里面的营业面积
			} else {
				data.put("${businessarea}", "");
			}
			
			Date d = shop.getEacooperationdate();
			if (!"".equals(d) && d != null) {
				String dateStr = new SimpleDateFormat("yyyy-MM-dd").format(d);
				data.put("${eacooperationdate}", dateStr);// 项目合作年限(客户主门店里面的合作开始时间)
			} else {
				data.put("${eacooperationdate}", "");
			}
			if (shop.getStoreinvamount() != null) {
				data.put("${storeinvamount}", nf.format(shop.getStoreinvamount()));// 存货金额，取客户门店中的“门店存货金额”
			} else {
				data.put("${storeinvamount}", "");
			}
			
			String shoprentend = "";
			if(shop.getCustomerShopId() != null){
				CustomerShopInfoEntityNew shopInfoEntityNew = shopInfoService.queryByIdnew(shop.getCustomerShopId());// 新门店信息
				if (shopInfoEntityNew.getShoprentend() != null) {
					shoprentend = new SimpleDateFormat("yyyy-MM-dd").format(shopInfoEntityNew.getShoprentend());
				} 
			}
			data.put("${shoprentend}", shoprentend);// 经营场地租赁合同到期日(即租赁合同止日期)
			
		}
		// 经营状况
		ManagementInfoEntity ma = managementInfoService.getByLoanNo(loanapplyNo);
		if (ma != null) {
			if (ma.getCapital() != null) {
				data.put("${totalAmount}", nf.format(ma.getCapital()));
			} else {
				data.put("${storeinvamount}", "");
			}
		}
		// 渠道数据
		String startCoopDate = "";//项目合作年限
		if (loanapply.getLoanType().equals(StatusContexts.LOAN_TYPE_BP)
				|| loanapply.getLoanType().equals(StatusContexts.LOAN_TYPE_BP_JX)
				|| loanapply.getLoanType().equals(StatusContexts.LOAN_TYPE_BK)) {// 终端贷、流通贷-厂家、流通贷-经销商:/rmongo/bk_info_view
			O2oLoanBkInfo bkInfo = o2oLoanBkService.getEntity(loanapplyNo);
			if (bkInfo != null) {
				if (bkInfo.getStartCoopDate() != null) {
					startCoopDate = new SimpleDateFormat("yyyy-MM-dd").format(bkInfo.getStartCoopDate());// 与渠道企业合作起始时间
				} 
			} 
		} else if (loanapply.getLoanType().equals(StatusContexts.LOAN_TYPE_SC)) {// 流通贷-商超:/rmongo/sc_info_lno;loanType=='SC'
			O2oLoanScInfo scInfo = scService.getLoanapplyNo(loanapplyNo);
			if (scInfo != null) {
				if (scInfo.getWhitelistTime() != null) {
					startCoopDate = new SimpleDateFormat("yyyy-MM-dd").format(scInfo.getWhitelistTime());// 与白名单内商超合作开始时间
				} 
			} 
		} else if (loanapply.getLoanType().equals(StatusContexts.LOAN_TYPE_SG)) {// 流通贷-蔬果:/rmongo/gs_info_lno
			O2oLoanGsInfo gsInfo = gsService.getLoanapplyNo(loanapplyNo);
			if (gsInfo != null) {
				if (gsInfo.getStartOperateTime() != null) {
					startCoopDate = new SimpleDateFormat("yyyy-MM-dd").format(gsInfo.getStartOperateTime());// 本市场经营开始时间
				}
			}
		}
		data.put("${startCoopDate}", startCoopDate);
		
		
		O2oMainShopInfoEntity O2oMainShop = mainShopInfoService.getByLoanNo(loanapplyNo);
		if (O2oMainShop != null) {
			if (O2oMainShop.getBusinesshours()!= null) {
				
				data.put("${storyearsName}", getyears(O2oMainShop.getBusinesshours()));//经营年限
			} 

		}else {
			
				data.put("${storyearsName}", "");
			
		}
		
		if (basic != null) {
			data.put("${loanName}", basic.getCustomerName());// 借款人姓名
			String sex = "";
			if ("F".equals(basic.getSex())) {
				sex = "女";
			} else if ("M".equals(basic.getSex())) {
				sex = "男";
			}
			data.put("${sex}", sex);// 借款人性别
			data.put("${idCard}", basic.getDocumentNo());// 身份证号码
			data.put("${mobileNumber}", basic.getUserPhone());// 借款人联系方式
			data.put("${age}", String.valueOf(IdNOToAge(basic.getDocumentNo())));// 借款人年龄
		}
		
		// 联系人
		if (mate != null && StringUtil.isNotBlank(mate.getSpouseId())) {// 配偶
			data.put("${linkmanName}", mate.getUserFullName());// 配偶姓名
			data.put("${linkmanMobile}", mate.getUserPhone());// 配偶手机号
		} else if (guarantor != null) {// 担保人
			data.put("${linkmanName}", guarantor.getUserFullName());// 担保人姓名
			data.put("${linkmanMobile}", guarantor.getUserPhone());// 担保人手机号
		} else {// 如无配偶和担保人则为空
			data.put("${linkmanName}", "");
			data.put("${linkmanMobile}", "");
		}
		
		if (loanapply != null) {
			if (!"".equals(loanapply.getEaMount()) && loanapply.getEaMount() != null) {
				//data.put("${eaMount}", nf.format(formatComma2BigDecimal(loanapply.getEaMount().divide(new BigDecimal(10000)))));// 支用限额(EA批复金额)(万元)
				//data.put("${eaMount}", String.valueOf(loanapply.getEaMount().setScale(2,BigDecimal.ROUND_HALF_DOWN)));// 支用限额	总部风险总监批复的EA批复金额,保留后面两个零
				data.put("${eaMount}", nf.format(loanapply.getEaMount()));// 支用限额	总部风险总监批复的EA批复金额
			}
			data.put("${loanTerm}", String.valueOf(loanapply.getLoanTerm()));// 贷款期限
			if (loanapply.getRepayMentway() != null) {// 还款方式
				if (loanapply.getRepayMentway().equals("AKT")) {
					data.put("${repayMentway}", "等额本金");// 还款方式
					data.put("repayMentwayNo", "(2)");
				} else if (loanapply.getRepayMentway().equals("RMT")) {
					data.put("${repayMentway}", "按月付息，到期还本");// 还款方式
					data.put("repayMentwayNo", "(1)");
				} else {
					data.put("${repayMentway}", "等额本息");// 还款方式
					data.put("repayMentwayNo", "(2)");
				}
			}
		}
		
		if (customerBasicInfo != null) {
			String recipientAdress="";//有效联系地址	借款人的收件地址
         	if (StringUtil.isNotBlank(customerBasicInfo.getRecipientProvince())) {
         		// 查数据字典--所在省，dd_no='9'
         		PubDditem p = pubDditemService.queryPubDditemCRM("9",customerBasicInfo.getRecipientProvince());// 所在省
				if (p != null) {
					recipientAdress=recipientAdress+p.getItemName();
				}
			}
        
			if (StringUtil.isNotBlank(customerBasicInfo.getRecipientCity())) {
				// 查数据字典--所在市，dd_no='10'
				PubDditem p = pubDditemService.queryPubDditemCRM("10",customerBasicInfo.getRecipientCity());// 所在市
				if (p != null) {
					recipientAdress=recipientAdress+p.getItemName();
				}
			}
			
			if (StringUtil.isNotBlank(customerBasicInfo.getRecipientCounty())) {
				PubDditem p = pubDditemService.queryPubDditemCRM("11",customerBasicInfo.getRecipientCounty());// 所在县
				if (p != null) {
					recipientAdress=recipientAdress+p.getItemName();
				}
			}

			if (customerBasicInfo.getRecipientAddress() != null) {
				recipientAdress = recipientAdress + customerBasicInfo.getRecipientAddress();
			}
			data.put("${recipientAdress}", recipientAdress);// 收件地址
			
		}else {
			data.put("${recipientAdress}", "");// 收件地址
		}
		
		return data;
	}
	/**
	 * 填充（浦发济南分行）放款通知书
	 * @param loanapplyNo
	 * @return
	 */
	private Map<String, String> fillSPDBJNRecommendation(String loanapplyNo,O2oLoanUserEntity basic,CustomerBasicInfo customerBasicInfo) {
		Map<String, String> data = new HashMap<>();
		O2oLoanapplyEntity loanapply = loanService.findById(loanapplyNo);
		if (loanapply == null) {
			return data;
		}
//		NumberFormat nf = new DecimalFormat(",###.00");
		NumberFormat nf = new DecimalFormat("#0.####");
		O2oLoanUserEntity mate = loanUserService.findSpouseId(basic.getLoanId(), loanapplyNo);//配偶
		O2oLoanUserEntity guarantor = loanUserService.queryDBById(loanapplyNo);//担保人
		CustomerShopInfoEntity shop = new CustomerShopInfoEntity();
		List<CustomerShopInfoEntity> infoList = shopInfoService.list(loanapplyNo);//门店
		if (!infoList.isEmpty()) {
			if (infoList.size() > 1) {
				for (CustomerShopInfoEntity shopInfo : infoList) {
					if (shopInfo.getShoptype().equals("MAN")) {// 客户主门店里面的营业面积
						shop = shopInfo;
					}
				}
			} else {
				shop = infoList.get(0);
			}
		}
		if (shop != null) {
			if (shop.getBusinessarea() != null) {
				data.put("${businessarea}", String.valueOf(shop.getBusinessarea()));// 客户主门店里面的营业面积
			} else {
				data.put("${businessarea}", "");
			}
			
			Date d = shop.getEacooperationdate();
			if (!"".equals(d) && d != null) {
				String dateStr = new SimpleDateFormat("yyyy-MM-dd").format(d);
				data.put("${eacooperationdate}", dateStr);// 项目合作年限(客户主门店里面的合作开始时间)
			} else {
				data.put("${eacooperationdate}", "");
			}
			if (shop.getStoreinvamount() != null) {
				data.put("${storeinvamount}", nf.format(shop.getStoreinvamount()));// 存货金额，取客户门店中的“门店存货金额”
			} else {
				data.put("${storeinvamount}", "");
			}
			
			if (shop.getPropertytype() != null&&"ZY".equals(shop.getPropertytype())) {
				data.put("${rentDate}", "长期");// 存货金额，取客户门店中的“门店存货金额”
			} else {
				data.put("${rentDate}", DateUtils.formateDateString(shop.getShoprentend(), "yyyy-MM-dd"));
				
			}
		}
		//经营状况
		ManagementInfoEntity ma=managementInfoService.getByLoanNo(loanapplyNo);
		if (ma!=null) {
			if (ma.getCapital()!=null) {
				data.put("${totalAmount}", nf.format(ma.getCapital()));
			}else {
				data.put("${storeinvamount}", "");
			}
		}
		// 渠道数据
		String startCoopDate = "";//项目合作年限
		if (loanapply.getLoanType().equals(StatusContexts.LOAN_TYPE_BP)
				|| loanapply.getLoanType().equals(StatusContexts.LOAN_TYPE_BP_JX)
				|| loanapply.getLoanType().equals(StatusContexts.LOAN_TYPE_BK)) {// 终端贷、流通贷-厂家、流通贷-经销商:/rmongo/bk_info_view
			O2oLoanBkInfo bkInfo = o2oLoanBkService.getEntity(loanapplyNo);
			if (bkInfo != null) {
				if (bkInfo.getStartCoopDate() != null) {
					startCoopDate = new SimpleDateFormat("yyyy-MM-dd").format(bkInfo.getStartCoopDate());// 与渠道企业合作起始时间
				} 
			} 
		} else if (loanapply.getLoanType().equals(StatusContexts.LOAN_TYPE_SC)) {// 流通贷-商超:/rmongo/sc_info_lno;loanType=='SC'
			O2oLoanScInfo scInfo = scService.getLoanapplyNo(loanapplyNo);
			if (scInfo != null) {
				if (scInfo.getWhitelistTime() != null) {
					startCoopDate = new SimpleDateFormat("yyyy-MM-dd").format(scInfo.getWhitelistTime());// 与白名单内商超合作开始时间
				} 
			} 
		} else if (loanapply.getLoanType().equals(StatusContexts.LOAN_TYPE_SG)) {// 流通贷-蔬果:/rmongo/gs_info_lno
			O2oLoanGsInfo gsInfo = gsService.getLoanapplyNo(loanapplyNo);
			if (gsInfo != null) {
				if (gsInfo.getStartOperateTime() != null) {
					startCoopDate = new SimpleDateFormat("yyyy-MM-dd").format(gsInfo.getStartOperateTime());// 本市场经营开始时间
				}
			}
		}
		data.put("${startCoopDate}", startCoopDate);
		
		
		O2oMainShopInfoEntity O2oMainShop = mainShopInfoService.getByLoanNo(loanapplyNo);
		if (O2oMainShop != null) {
			if (O2oMainShop.getBusinesshours()!= null) {
				
				data.put("${storyearsName}", getyears(O2oMainShop.getBusinesshours()));//经营年限
			} 

		}else {
			
				data.put("${storyearsName}", "");
			
		}
		
		if (basic != null) {
			data.put("${loanName}", basic.getCustomerName());// 借款人姓名
			String sex = "";
			if ("F".equals(basic.getSex())) {
				sex = "女";
			} else if ("M".equals(basic.getSex())) {
				sex = "男";
			}
			data.put("${sex}", sex);// 借款人性别
			data.put("${idCard}", basic.getDocumentNo());// 身份证号码
			data.put("${mobileNumber}", basic.getUserPhone());// 借款人联系方式
			data.put("${age}", String.valueOf(IdNOToAge(basic.getDocumentNo())));// 借款人年龄
		}
		
		// 联系人
		if (mate != null && StringUtil.isNotBlank(mate.getSpouseId())) {// 配偶
			data.put("${linkmanName}", mate.getUserFullName());// 配偶姓名
			data.put("${linkmanMobile}", mate.getUserPhone());// 配偶手机号
		} else if (guarantor != null) {// 担保人
			data.put("${linkmanName}", guarantor.getUserFullName());// 担保人姓名
			data.put("${linkmanMobile}", guarantor.getUserPhone());// 担保人手机号
		} else {// 如无配偶和担保人则为空
			data.put("${linkmanName}", "");
			data.put("${linkmanMobile}", "");
		}
		
		if (loanapply != null) {
			if (!"".equals(loanapply.getEaMount()) && loanapply.getEaMount() != null) {
				//data.put("${eaMount}", nf.format(formatComma2BigDecimal(loanapply.getEaMount().divide(new BigDecimal(10000)))));// 支用限额(EA批复金额)(万元)
				//data.put("${eaMount}", String.valueOf(loanapply.getEaMount().setScale(2,BigDecimal.ROUND_HALF_DOWN)));// 支用限额	总部风险总监批复的EA批复金额,保留后面两个零
				data.put("${eaMount}", nf.format(loanapply.getEaMount()));// 支用限额	总部风险总监批复的EA批复金额
			}
			data.put("${loanTerm}", String.valueOf(loanapply.getLoanTerm()));// 贷款期限
			if (loanapply.getRepayMentway() != null) {// 还款方式
				if (loanapply.getRepayMentway().equals("AKT")) {
					data.put("${repayMentway}", "等额本金");// 还款方式
					data.put("repayMentwayNo", "(2)");
				} else if (loanapply.getRepayMentway().equals("RMT")) {
					data.put("${repayMentway}", "按月付息，到期还本");// 还款方式
					data.put("repayMentwayNo", "(1)");
				} else {
					data.put("${repayMentway}", "等额本息");// 还款方式
					data.put("repayMentwayNo", "(2)");
				}
			}
		}
		
		if (customerBasicInfo != null) {
			String recipientAdress="";//有效联系地址	借款人的收件地址
         	if (StringUtil.isNotBlank(customerBasicInfo.getRecipientProvince())) {
         		// 查数据字典--所在省，dd_no='9'
         		PubDditem p = pubDditemService.queryPubDditemCRM("9",customerBasicInfo.getRecipientProvince());// 所在省
				if (p != null) {
					recipientAdress=recipientAdress+p.getItemName();
				}
			}
        
			if (StringUtil.isNotBlank(customerBasicInfo.getRecipientCity())) {
				// 查数据字典--所在市，dd_no='10'
				PubDditem p = pubDditemService.queryPubDditemCRM("10",customerBasicInfo.getRecipientCity());// 所在市
				if (p != null) {
					recipientAdress=recipientAdress+p.getItemName();
				}
			}
			
			if (StringUtil.isNotBlank(customerBasicInfo.getRecipientCounty())) {
				PubDditem p = pubDditemService.queryPubDditemCRM("11",customerBasicInfo.getRecipientCounty());// 所在县
				if (p != null) {
					recipientAdress=recipientAdress+p.getItemName();
				}
			}

			if (customerBasicInfo.getRecipientAddress() != null) {
				recipientAdress = recipientAdress + customerBasicInfo.getRecipientAddress();
			}
			data.put("${recipientAdress}", recipientAdress);// 收件地址
			
		}else {
			data.put("${recipientAdress}", "");// 收件地址
		}
		
		return data;
	}
	/**
	 * 填充（齐鲁银行）放款通知书
	 * @param loanapplyNo
	 * @return
	 */
	private Map<String, String> fillQLBRecommendation(String loanapplyNo,O2oLoanUserEntity basic,CustomerBasicInfo customerBasicInfo) {
		Map<String, String> data = new HashMap<>();
		O2oLoanapplyEntity loanapply = loanService.findById(loanapplyNo);
		if (loanapply == null) {
			return data;
		}
		NumberFormat nf = new DecimalFormat("#0.####");
		O2oLoanUserEntity mate = loanUserService.findSpouseId(basic.getLoanId(), loanapplyNo);//配偶
		O2oLoanUserEntity guarantor = loanUserService.queryDBById(loanapplyNo);//担保人
		
		
		int loanCount = loanUserService.getLoanerCount(loanapply.getLoanId());// 历史贷款次数
		int numberOfLoans = loanCount + 1;// 在怡亚通申请贷款次数取“历史贷款次数”加上本次贷款
		data.put("${numberOfLoans}", String.valueOf(numberOfLoans));

		O2oMainShopInfoEntity shop = mainShopInfoService.getByLoanNo(loanapplyNo);
		if(shop!=null){
			
			if(StringUtils.isNotEmpty(shop.getVocation())){
				PubDditem p = pubDditemService.queryPubDditemO2o("l6rkja9fqcb0a",shop.getVocation());// 职业
				if(p!=null){
					data.put("${vocation}", p.getItemName());
				}
			}
		}
		String eapurchaseamount=" ";
		O2oLoanBkInfo bkInfo = o2oLoanBkService.getEntity(loanapplyNo);
		if (bkInfo != null) {

			if (bkInfo.getMonthPrice() != null) {
				eapurchaseamount=nf.format(bkInfo.getMonthPrice().divide(new BigDecimal(10000)));
//				data.put("${eapurchaseamount}", nf.format(bkInfo.getMonthPrice().divide(new BigDecimal(10000))));// 向怡亚通月均采购额（以近6个月金额为标准）/【万元】
			}

		}
		data.put("${eapurchaseamount}",eapurchaseamount);

		if (basic != null) {
			data.put("${loanName}", basic.getCustomerName());// 借款人姓名
			String sex = "";
			if ("F".equals(basic.getSex())) {
				sex = "女";
			} else if ("M".equals(basic.getSex())) {
				sex = "男";
			}
			data.put("${sex}", sex);// 借款人性别
			data.put("${idCard}", basic.getDocumentNo());// 身份证号码
			data.put("${mobileNumber}", basic.getUserPhone());// 借款人联系方式
			data.put("${age}", String.valueOf(IdNOToAge(basic.getDocumentNo())));// 借款人年龄
		}

		// 联系人
		if (mate != null && StringUtil.isNotBlank(mate.getSpouseId())) {// 配偶
			data.put("${linkmanName}", mate.getUserFullName());// 配偶姓名
			data.put("${linkmanMobile}", mate.getUserPhone());// 配偶手机号
		} else if (guarantor != null) {// 担保人
			data.put("${linkmanName}", guarantor.getUserFullName());// 担保人姓名
			data.put("${linkmanMobile}", guarantor.getUserPhone());// 担保人手机号
		} else {// 如无配偶和担保人则为空
			data.put("${linkmanName}", "");
			data.put("${linkmanMobile}", "");
		}
		
		if (loanapply != null) {
			if (!"".equals(loanapply.getEaMount()) && loanapply.getEaMount() != null) {
				//data.put("${eaMount}", String.valueOf(loanapply.getEaMount().setScale(2,BigDecimal.ROUND_HALF_DOWN)));// 支用限额	总部风险总监批复的EA批复金额,保留后面两个零
				data.put("${eaMount}", nf.format(loanapply.getEaMount().divide(new BigDecimal(10000))));// EA批复金额【万元】
			}
			data.put("${loanTerm}", String.valueOf(loanapply.getLoanTerm()));// 贷款期限
			data.put("${loanaMount}", nf.format(loanapply.getLoanaMount().divide(new BigDecimal(10000))));// 申请金额【万元】,例如66666，显示6.7万
			if (loanapply.getRepayMentway() != null) {// 还款方式
				if (loanapply.getRepayMentway().equals("AKT")) {
					data.put("${repayMentway}", "等额本金");// 还款方式
					data.put("repayMentwayNo", "(2)");
				} else if (loanapply.getRepayMentway().equals("RMT")) {
					data.put("${repayMentway}", "按月付息，到期还本");// 还款方式
					data.put("repayMentwayNo", "(1)");
				} else {
					data.put("${repayMentway}", "等额本息");// 还款方式
					data.put("repayMentwayNo", "(2)");
				}
			}
		}
		
		if (customerBasicInfo != null) {
			String recipientAdress="";//有效联系地址	借款人的收件地址
			if (StringUtil.isNotBlank(customerBasicInfo.getRecipientProvince())) {
				// 查数据字典--所在省，dd_no='9'
				PubDditem p = pubDditemService.queryPubDditemCRM("9",customerBasicInfo.getRecipientProvince());// 所在省
				if (p != null) {
					recipientAdress=recipientAdress+p.getItemName();
				}
			}
			
			if (StringUtil.isNotBlank(customerBasicInfo.getRecipientCity())) {
				// 查数据字典--所在市，dd_no='10'
				PubDditem p = pubDditemService.queryPubDditemCRM("10",customerBasicInfo.getRecipientCity());// 所在市
				if (p != null) {
					recipientAdress=recipientAdress+p.getItemName();
				}
			}
			
			if (StringUtil.isNotBlank(customerBasicInfo.getRecipientCounty())) {
				PubDditem p = pubDditemService.queryPubDditemCRM("11",customerBasicInfo.getRecipientCounty());// 所在县
				if (p != null) {
					recipientAdress=recipientAdress+p.getItemName();
				}
			}
			
			if (customerBasicInfo.getRecipientAddress() != null) {
				recipientAdress = recipientAdress + customerBasicInfo.getRecipientAddress();
			}
			data.put("${recipientAdress}", recipientAdress);// 收件地址
			
		}else {
			data.put("${recipientAdress}", "");// 收件地址
		}
		
		return data;
	}
	
	/**
	 * 填充（国安村镇银行）推荐函
	 * @param loanapplyNo
	 * @return
	 */
	private Map<String, String> fillGACZRecommendation(String loanapplyNo,O2oLoanUserEntity basic,CustomerBasicInfo customerBasicInfo) {
		Map<String, String> data = new HashMap<>();
		O2oLoanapplyEntity loanapply = loanService.findById(loanapplyNo);
		if (loanapply == null) {
			return data;
		}
//		NumberFormat nf = new DecimalFormat(",###.00");
		NumberFormat nf = new DecimalFormat("#0.####");
		O2oLoanUserEntity mate = loanUserService.findSpouseId(basic.getLoanId(), loanapplyNo);//配偶
		O2oLoanUserEntity guarantor = loanUserService.queryDBById(loanapplyNo);//担保人
		
		
		int loanCount = loanUserService.getLoanerCount(loanapply.getLoanId());// 历史贷款次数
		int numberOfLoans = loanCount + 1;// 在怡亚通申请贷款次数取“历史贷款次数”加上本次贷款
		data.put("${numberOfLoans}",  String.valueOf(numberOfLoans));
		
		O2oMainShopInfoEntity shop = mainShopInfoService.getByLoanNo(loanapplyNo);
		if(shop!=null){
			
			if(StringUtils.isNotEmpty(shop.getVocation())){
				PubDditem p = pubDditemService.queryPubDditemO2o("l6rkja9fqcb0a",shop.getVocation());// 职业
				if(p!=null){
					data.put("${vocation}", p.getItemName());
				}
			}
		}
		
		O2oLoanBkInfo bkInfo = o2oLoanBkService.getEntity(loanapplyNo);
		if (bkInfo != null) {

			if (bkInfo.getMonthPrice() != null) {
				data.put("${eapurchaseamount}", nf.format(bkInfo.getMonthPrice().divide(new BigDecimal(10000))));// 向怡亚通月均采购额（以近6个月金额为标准）/【万元】
			} else {
				data.put("${eapurchaseamount}", "");
			}
		}
		
		if (basic != null) {
			data.put("${loanName}", basic.getCustomerName());// 借款人姓名
			String sex = "";
			if ("F".equals(basic.getSex())) {
				sex = "女";
			} else if ("M".equals(basic.getSex())) {
				sex = "男";
			}
			data.put("${sex}", sex);// 借款人性别
			data.put("${idCard}", basic.getDocumentNo());// 身份证号码
			data.put("${mobileNumber}", basic.getUserPhone());// 借款人联系方式
			data.put("${age}", String.valueOf(IdNOToAge(basic.getDocumentNo())));// 借款人年龄
		}
		
		// 联系人
		if (mate != null && StringUtil.isNotBlank(mate.getSpouseId())) {// 配偶
			data.put("${linkmanName}", mate.getUserFullName());// 配偶姓名
			data.put("${linkmanMobile}", mate.getUserPhone());// 配偶手机号
		} else if (guarantor != null) {// 担保人
			data.put("${linkmanName}", guarantor.getUserFullName());// 担保人姓名
			data.put("${linkmanMobile}", guarantor.getUserPhone());// 担保人手机号
		} else {// 如无配偶和担保人则为空
			data.put("${linkmanName}", "");
			data.put("${linkmanMobile}", "");
		}
		
		if (loanapply != null) {
			if (!"".equals(loanapply.getEaMount()) && loanapply.getEaMount() != null) {
				data.put("${eaMount}", nf.format(loanapply.getEaMount().divide(new BigDecimal(10000))));// 审批金额/支用限额(EA批复金额)【万元】
				//data.put("${eaMount}", String.valueOf(loanapply.getEaMount().setScale(2,BigDecimal.ROUND_HALF_DOWN)));// 支用限额	总部风险总监批复的EA批复金额,保留后面两个零
				//data.put("${eaMount}", nf.format(formatComma2BigDecimal(loanapply.getEaMount())));// 支用限额	总部风险总监批复的EA批复金额
			}
			data.put("${loanTerm}", String.valueOf(loanapply.getLoanTerm()));// 贷款期限
			data.put("${loanaMount}", nf.format(loanapply.getLoanaMount().divide(new BigDecimal(10000))));// 申请金额【万元】
			if (loanapply.getRepayMentway() != null) {// 还款方式
				if (loanapply.getRepayMentway().equals("AKT")) {
					data.put("${repayMentway}", "等额本金");// 还款方式
					data.put("repayMentwayNo", "(2)");
				} else if (loanapply.getRepayMentway().equals("RMT")) {
					data.put("${repayMentway}", "按月付息，到期还本");// 还款方式
					data.put("repayMentwayNo", "(1)");
				} else {
					data.put("${repayMentway}", "等额本息");// 还款方式
					data.put("repayMentwayNo", "(2)");
				}
			}
		}
		
		if (customerBasicInfo != null) {
			String recipientAdress="";//有效联系地址	借款人的收件地址
			if (StringUtil.isNotBlank(customerBasicInfo.getRecipientProvince())) {
				// 查数据字典--所在省，dd_no='9'
				PubDditem p = pubDditemService.queryPubDditemCRM("9",customerBasicInfo.getRecipientProvince());// 所在省
				if (p != null) {
					recipientAdress=recipientAdress+p.getItemName();
				}
			}
			
			if (StringUtil.isNotBlank(customerBasicInfo.getRecipientCity())) {
				// 查数据字典--所在市，dd_no='10'
				PubDditem p = pubDditemService.queryPubDditemCRM("10",customerBasicInfo.getRecipientCity());// 所在市
				if (p != null) {
					recipientAdress=recipientAdress+p.getItemName();
				}
			}
			
			if (StringUtil.isNotBlank(customerBasicInfo.getRecipientCounty())) {
				PubDditem p = pubDditemService.queryPubDditemCRM("11",customerBasicInfo.getRecipientCounty());// 所在县
				if (p != null) {
					recipientAdress=recipientAdress+p.getItemName();
				}
			}
			
			if (customerBasicInfo.getRecipientAddress() != null) {
				recipientAdress = recipientAdress + customerBasicInfo.getRecipientAddress();
			}
			data.put("${recipientAdress}", recipientAdress);// 收件地址
			
			
		}else {
			data.put("${recipientAdress}", "");// 收件地址
		}
		
		return data;
	}
	
	/**
	 * 填充（郑州银行）放款通知书
	 * @param loanapplyNo
	 * @return
	 */
	private Map<String, String> fillZZBRecommendation(String loanapplyNo,O2oLoanUserEntity basic,CustomerBasicInfo customerBasicInfo) {
		Map<String, String> data = new HashMap<>();
		O2oLoanapplyEntity loanapply = loanService.findById(loanapplyNo);
		if (loanapply == null) {
			return data;
		}
//		NumberFormat nf = new DecimalFormat(",###.00");
		NumberFormat nf = new DecimalFormat("#0.####");
		O2oLoanUserEntity mate = loanUserService.findSpouseId(basic.getLoanId(), loanapplyNo);//配偶
		O2oLoanUserEntity guarantor = loanUserService.queryDBById(loanapplyNo);//担保人
		CustomerShopInfoEntity shop = new CustomerShopInfoEntity();
		List<CustomerShopInfoEntity> infoList = shopInfoService.list(loanapplyNo);//门店
		if (!infoList.isEmpty()) {
			if (infoList.size() > 1) {
				for (CustomerShopInfoEntity shopInfo : infoList) {
					if (shopInfo.getShoptype().equals("MAN")) {// 客户主门店里面的营业面积
						shop = shopInfo;
					}
				}
			} else {
				shop = infoList.get(0);
			}
		}
		
		int loanCount = loanUserService.getLoanerCount(loanapply.getLoanId());// 历史贷款次数
		int numberOfLoans = loanCount + 1;// 在怡亚通申请贷款次数取“历史贷款次数”加上本次贷款
		data.put("${numberOfLoans}",  String.valueOf(numberOfLoans));
		
		if (shop != null) {
			if (shop.getBusinessarea() != null) {
				data.put("${businessarea}", String.valueOf(shop.getBusinessarea()));// 客户主门店里面的营业面积
			} else {
				data.put("${businessarea}", "");
			}
			
			Date d = shop.getEacooperationdate();
			if (!"".equals(d) && d != null) {
				String dateStr = new SimpleDateFormat("yyyy-MM-dd").format(d);
				data.put("${eacooperationdate}", dateStr);// 与怡亚通合作年限、项目合作年限(客户主门店里面的合作开始时间)
			} else {
				data.put("${eacooperationdate}", "");
			}
			
			if (shop.getStoryears() != null) {
				// 查数据字典--门店成立年限，dd_no='8'
				PubDditem p = pubDditemService.queryPubDditemCRM("8", shop.getStoryears());
				data.put("${storyearsName}", p.getItemName());// 从业年限(客户主门店成立年限) 经营年限
			} else {
				data.put("${storyearsName}", "");
			}
			
			if (shop.getTotalAmount() != null) {
//				data.put("${totalAmount}", nf.format(formatComma2BigDecimal(shop.getTotalAmount())));// 全年销售收入/年销售额(客户主门店里面的所有门店年销售额)
				data.put("${totalAmount}", nf.format(shop.getTotalAmount().divide(new BigDecimal(10000))));// 全年销售收入(客户主门店里面的所有门店年销售额)(万元)
			} else {
				data.put("${totalAmount}", "");
			}
			
			if (shop.getEapurchaseamount() != null) {
//				data.put("${eapurchaseamount}", String.valueOf(shop.getEapurchaseamount()));// 向怡亚通月均采购额（以近6个月金额为标准）/元
				data.put("${eapurchaseamount}", nf.format(shop.getEapurchaseamount().divide(new BigDecimal(10000))));// 向怡亚通月均采购额（以近6个月金额为标准）/【万元】
			} else {
				data.put("${eapurchaseamount}", "");
			}
		}
		
		if (basic != null) {
			data.put("${loanName}", basic.getCustomerName());// 借款人姓名
			String sex = "";
			if ("F".equals(basic.getSex())) {
				sex = "女";
			} else if ("M".equals(basic.getSex())) {
				sex = "男";
			}
			data.put("${sex}", sex);// 借款人性别
			data.put("${idCard}", basic.getDocumentNo());// 身份证号码
			data.put("${mobileNumber}", basic.getUserPhone());// 借款人联系方式
			data.put("${age}", String.valueOf(IdNOToAge(basic.getDocumentNo())));// 借款人年龄
		}
		
		// 联系人
		if (mate != null && StringUtil.isNotBlank(mate.getSpouseId())) {// 配偶
			data.put("${linkmanName}", mate.getUserFullName());// 配偶姓名
			data.put("${linkmanMobile}", mate.getUserPhone());// 配偶手机号
		} else if (guarantor != null) {// 担保人
			data.put("${linkmanName}", guarantor.getUserFullName());// 担保人姓名
			data.put("${linkmanMobile}", guarantor.getUserPhone());// 担保人手机号
		} else {// 如无配偶和担保人则为空
			data.put("${linkmanName}", "");
			data.put("${linkmanMobile}", "");
		}
		
		if (loanapply != null) {
			if (!"".equals(loanapply.getEaMount()) && loanapply.getEaMount() != null) {
//				data.put("${eaMount}", nf.format(formatComma2BigDecimal(loanapply.getEaMount().divide(new BigDecimal(10000)))));// 审批金额/支用限额(EA批复金额)【万元】
//				data.put("${eaMount}", String.valueOf(loanapply.getEaMount().setScale(2,BigDecimal.ROUND_HALF_DOWN)));// 支用限额	总部风险总监批复的EA批复金额,保留后面两个零
				data.put("${eaMount}", nf.format(loanapply.getEaMount()));// EA批复金额(元)
			}
			data.put("${loanTerm}", String.valueOf(loanapply.getLoanTerm()));// 贷款期限
			data.put("${loanaMount}", nf.format(loanapply.getLoanaMount().divide(new BigDecimal(10000))));// 申请金额【万元】
			if (loanapply.getRepayMentway() != null) {// 还款方式
				if (loanapply.getRepayMentway().equals("AKT")) {
					data.put("${repayMentway}", "等额本金");// 还款方式
					data.put("repayMentwayNo", "(2)");
				} else if (loanapply.getRepayMentway().equals("RMT")) {
					data.put("${repayMentway}", "按月付息，到期还本");// 还款方式
					data.put("repayMentwayNo", "(1)");
				} else {
					data.put("${repayMentway}", "等额本息");// 还款方式
					data.put("repayMentwayNo", "(2)");
				}
			}
		}
		
		if (customerBasicInfo != null) {
			String recipientAdress="";//有效联系地址	借款人的收件地址
			if (StringUtil.isNotBlank(customerBasicInfo.getRecipientProvince())) {
				// 查数据字典--所在省，dd_no='9'
				PubDditem p = pubDditemService.queryPubDditemCRM("9",customerBasicInfo.getRecipientProvince());// 所在省
				if (p != null) {
					recipientAdress=recipientAdress+p.getItemName();
				}
			}
			
			if (StringUtil.isNotBlank(customerBasicInfo.getRecipientCity())) {
				// 查数据字典--所在市，dd_no='10'
				PubDditem p = pubDditemService.queryPubDditemCRM("10",customerBasicInfo.getRecipientCity());// 所在市
				if (p != null) {
					recipientAdress=recipientAdress+p.getItemName();
				}
			}
			
			if (StringUtil.isNotBlank(customerBasicInfo.getRecipientCounty())) {
				PubDditem p = pubDditemService.queryPubDditemCRM("11",customerBasicInfo.getRecipientCounty());// 所在县
				if (p != null) {
					recipientAdress=recipientAdress+p.getItemName();
				}
			}
			
			if (customerBasicInfo.getRecipientAddress() != null) {
				recipientAdress = recipientAdress + customerBasicInfo.getRecipientAddress();
			}
			data.put("${recipientAdress}", recipientAdress);// 收件地址
			
		}else {
			data.put("${recipientAdress}", "");// 收件地址
		}
		
		return data;
	}

	/**
	 * 填充（国安村镇银行）放款通知书
	 * @param loanapplyNo
	 * @param basic
	 * @param customerBasicInfo
	 * @return
	 */
	private Map<String, Object> fillFK_GACZLoanAdvice(String loanapplyNo,O2oLoanUserEntity basic,CustomerBasicInfo customerBasicInfo) {
		Map<String, Object> data = new HashMap<>();
		O2oLoanapplyEntity loanapply = loanService.findById(loanapplyNo);
		if (loanapply == null) {
			return data;
		}
		NumberFormat nf = new DecimalFormat("#0.####");
		
		
		
		O2oMainMonthInfoEntity info = mainMonthInfoService.getByLoanNo(loanapplyNo);

		if(info!=null){
			BigDecimal monthAmount=new BigDecimal(0);
			monthAmount=info.getTurnover1th().add(info.getTurnover2th()).add(info.getTurnover3th()).add(info.getTurnover4th()).add(info.getTurnover5th().add(info.getTurnover6th()));
			if (monthAmount != null) {
				data.put("monthAmount", nf.format(monthAmount.divide(new BigDecimal(6), 2, BigDecimal.ROUND_UP)));// “月均营业额”取数客户主门店中“所有门店年销售额/12”,除以12,保留两位小数
			} else {
				data.put("monthAmount", "");
			}
		}
		O2oLoanBkInfo bkInfo = o2oLoanBkService.getEntity(loanapplyNo);
		if (bkInfo != null) {

			if (bkInfo.getMonthPrice() != null) {
				data.put("${eapurchaseamount}", nf.format(bkInfo.getMonthPrice().divide(new BigDecimal(10000))));// 向怡亚通月均采购额（以近6个月金额为标准）/【万元】
			} else {
				data.put("${eapurchaseamount}", "");
			}
		}
		
		
		if (basic != null) {
			data.put("loanName", basic.getUserFullName());// 借款人
			data.put("idCard", basic.getDocumentNo());// 身份证号码
		}
		
		if (customerBasicInfo != null) {
			String recipientAdress="";//有效联系地址	借款人的收件地址
			if (StringUtil.isNotBlank(customerBasicInfo.getRecipientProvince())) {
				// 查数据字典--所在省，dd_no='9'
				PubDditem p = pubDditemService.queryPubDditemCRM("9",customerBasicInfo.getRecipientProvince());// 所在省
				//PubDditem p = customerInfoService.getCustomerRecipientAddress(expan.getRecipientProvince(),"9");// 所在省
				if (p != null) {
					recipientAdress=recipientAdress+p.getItemName();
				}
			}
			
			if (StringUtil.isNotBlank(customerBasicInfo.getRecipientCity())) {
				// 查数据字典--所在市，dd_no='10'
				PubDditem p = pubDditemService.queryPubDditemCRM("10",customerBasicInfo.getRecipientCity());// 所在市
				//PubDditem p = customerInfoService.getCustomerRecipientAddress(expan.getRecipientCity(),"10");// 所在市
				if (p != null) {
					recipientAdress=recipientAdress+p.getItemName();
				}
			}
			
			if (StringUtil.isNotBlank(customerBasicInfo.getRecipientCounty())) {
				PubDditem p = pubDditemService.queryPubDditemCRM("11",customerBasicInfo.getRecipientCounty());// 所在县
				//PubDditem p = customerInfoService.getCustomerRecipientAddress(expan.getRecipientCounty(),"11");// 所在县
				if (p != null) {
					recipientAdress=recipientAdress+p.getItemName();
				}
			}
			
			if (customerBasicInfo.getRecipientAddress() != null) {
				recipientAdress = recipientAdress + customerBasicInfo.getRecipientAddress();
			}
			data.put("recipientAddress", recipientAdress);// 收件地址
		}else {
			data.put("recipientAddress", "");// 收件地址
		}
		
		if (loanapply != null) {
			if (!"".equals(loanapply.getEaMount()) && loanapply.getEaMount() != null) {
//				data.put("eaMount", nf.format(loanapply.getEaMount().divide(new BigDecimal(10000))));//EA批复金额【万元】
				data.put("eaMount", nf.format(loanapply.getEaMount()));// EA批复金额(元)
			}
			data.put("DKBillCode", "国安-借-"+loanapply.getBillCode());// ‘’贷款合同编号‘’取数“国安-借-贷款单号”
			data.put("ltdCode", loanapply.getLtdCode());// 经办平台
			data.put("ltdName", loanapply.getLtdName());// 经办平台
			data.put("receiveBank", loanapply.getReceiveBank());// “收款银行”取数“开户行全称”
			data.put("bankAccount", loanapply.getBankAccount());// “收款账号”取数“银行卡号”
			data.put("endBankDate", loanapply.getEndBankDate());// 到期日
			data.put("paymentTime", loanapply.getPaymentTime());// 放款日
			data.put("loanrate", nf.format(loanapply.getLoanrate().multiply(new BigDecimal(100))));// 年利率、贷款利率,乘以100
		}
		
		return data;
	}
	
	/**
	 * 填充江西银行推荐函
	 * @param loanapplyNo
	 * @param basic
	 * @param customerBasicInfo
	 * @return
	 */
	private Map<String, Object> fillLoanAdvice(String loanapplyNo,O2oLoanUserEntity basic,CustomerBasicInfo customerBasicInfo) {
		Map<String, Object> data = new HashMap<>();
		O2oLoanapplyEntity loanapply = loanService.findById(loanapplyNo);
		if (loanapply == null) {
			return data;
		}
		NumberFormat nf = new DecimalFormat("#0.####");
		//经营主体信息
		O2oMainShopInfoEntity shop = mainShopInfoService.getByLoanNo(loanapplyNo);
		//经营状况
		ManagementInfoEntity ma=managementInfoService.getByLoanNo(loanapplyNo);
		
		String loanmMy=" ";
		if (ma!=null) {
			if (ma.getCapital()!=null) {
				loanmMy=toEaMountZS(ma.getCapital().divide(new BigDecimal(10000)));// 年营业额
			
			}
			
		}
		
		data.put("loanmy", loanmMy);// 年营业额
		
		String eapurchaseamount=" ";
		O2oLoanBkInfo bkInfo = o2oLoanBkService.getEntity(loanapplyNo);
		if (bkInfo != null) {

			if (bkInfo.getMonthPrice() != null) {
				eapurchaseamount=nf.format(bkInfo.getMonthPrice().divide(new BigDecimal(10000)));	
			}

		}
		data.put("chamount",eapurchaseamount);
		
		
		if (shop != null) {
			data.put("licenceName", shop.getLicenceName());// 营业执照名字
		
			data.put("licenceAddress", getShopeJZAdress(shop));// 企业经营地址
		}
		
		if (basic != null) {
			data.put("loanName", basic.getUserFullName());// 借款人
			data.put("idCard", basic.getDocumentNo());// 身份证号码
		}
		
		if (customerBasicInfo != null) {
			String recipientAdress="";//有效联系地址	借款人的收件地址
         	if (StringUtil.isNotBlank(customerBasicInfo.getRecipientProvince())) {
         		// 查数据字典--所在省，dd_no='9'
         		PubDditem p = pubDditemService.queryPubDditemCRM("9",customerBasicInfo.getRecipientProvince());// 所在省
				//PubDditem p = customerInfoService.getCustomerRecipientAddress(expan.getRecipientProvince(),"9");// 所在省
				if (p != null) {
					recipientAdress=recipientAdress+p.getItemName();
				}
			}
        
			if (StringUtil.isNotBlank(customerBasicInfo.getRecipientCity())) {
				// 查数据字典--所在市，dd_no='10'
				PubDditem p = pubDditemService.queryPubDditemCRM("10",customerBasicInfo.getRecipientCity());// 所在市
				//PubDditem p = customerInfoService.getCustomerRecipientAddress(expan.getRecipientCity(),"10");// 所在市
				if (p != null) {
					recipientAdress=recipientAdress+p.getItemName();
				}
			}
			
			if (StringUtil.isNotBlank(customerBasicInfo.getRecipientCounty())) {
				PubDditem p = pubDditemService.queryPubDditemCRM("11",customerBasicInfo.getRecipientCounty());// 所在县
				//PubDditem p = customerInfoService.getCustomerRecipientAddress(expan.getRecipientCounty(),"11");// 所在县
				if (p != null) {
					recipientAdress=recipientAdress+p.getItemName();
				}
			}

			if (customerBasicInfo.getRecipientAddress() != null) {
				recipientAdress = recipientAdress + customerBasicInfo.getRecipientAddress();
			}
			data.put("recipientAddress", recipientAdress);// 收件地址
		}else {
			data.put("recipientAddress", "");// 收件地址
		}

		if (loanapply != null) {
			if (!"".equals(loanapply.getEaMount()) && loanapply.getEaMount() != null) {
				data.put("eaMount", nf.format(loanapply.getEaMount().divide(new BigDecimal(10000))));// 银行批复金额小写【万元】
			}
		}
		
		return data;
	}


	



	// 根据身份证号输出年龄
	public static int IdNOToAge(String IdNO) {
		int leh = IdNO.length();
		String dates = "";
		if (leh == 18) {
			dates = IdNO.substring(6, 10);
			SimpleDateFormat df = new SimpleDateFormat("yyyy");
			String year = df.format(new Date());
			int u = Integer.parseInt(year) - Integer.parseInt(dates);
			return u;
		} else {
			dates = IdNO.substring(6, 8);
			return Integer.parseInt(dates);
		}

	}
	
	private String getyears(Date date) {
		String str="0年";
		int year = 1;
		Date nowDate = new Date();
		java.util.Calendar c = Calendar.getInstance();
		c.setTime(date);
		int y1 = c.get(Calendar.YEAR);
		int m1 = c.get(Calendar.MONTH);
		c.setTime(nowDate);
		int y2 = c.get(Calendar.YEAR);
		int m2 = c.get(Calendar.MONTH);

		int y = y2 - y1;
		int m = y * 12 + m2 - m1;
		if(m>0){
			year=m/12;
		}else {
			return str;
		}
		if(year<1){
			str=1+"年";
		}else {
			str=year+1+"年";
		}
        
		System.out.println("实际相差年: " + y);
		System.out.println("相差月: " + m);
		System.out.println("str: " + str);
		return str;

	}
	
	/**
	 * @Title: getShopeJZAdress
	 * @Description: 查询营业执照地址
	 * @author 张庆奇
	 * @param shop
	 * @return
	 * @return String
	 * @throws
	 * @date 2017年11月7日 下午3:38:05
	 */
	private String getShopeJZAdress(O2oMainShopInfoEntity shop) {//门店地址
		String shopaddress = "";
		if (StringUtil.isNotBlank(shop.getShopprovince())) {
			PubDditem p = pubDditemService.queryPubDditemCRM("9", shop.getShopprovince());
			if (p != null) {
				shopaddress = shopaddress + p.getItemName();
			}
		}

		if (StringUtil.isNotBlank(shop.getShopcity())) {
			PubDditem p = pubDditemService.queryPubDditemCRM("10", shop.getShopcity());
			if (p != null) {
				shopaddress = shopaddress + p.getItemName();
			}
		}

		if (StringUtil.isNotBlank(shop.getShopcounty())) {
			PubDditem p = pubDditemService.queryPubDditemCRM("11", shop.getShopcounty());
			if (p != null) {
				shopaddress = shopaddress + p.getItemName();
			}
		}

		if (shop.getShopaddress() != null) {
			shopaddress = shopaddress + shop.getShopaddress();
		}
		return shopaddress;

	}

	public String toEaMountZS(Object d) {
		DecimalFormat df = new DecimalFormat("#");
		return df.format(d);
	}
		
	public String toEaMountM(Object d) {
		DecimalFormat df = new DecimalFormat("#");
		return df.format(d);
	}
}
